jQuery(document).ready( function() {	
	jQuery('.usersButton').on('click', function() {
 	    jQuery('.actionResult').hide();
		jQuery('.message').hide();
		if(jQuery('.users').is(":visible")){
			jQuery('.users').hide();
			jQuery('.usersButton').val('Alle Benutzer anzeigen');
		}else{
			jQuery('.users').show();
			jQuery('.usersButton').val('Benutzer verstecken');
		}
	});
	
	jQuery(".searchButton").on('click', function() {
		var searchWord = jQuery('.searchText').val();
		  /* Send the data using get and put the results in a div */
		jQuery.ajax({
	            url : "getUser",
	            type: "POST",
	            dataType: 'json',
	            data: "email=" + searchWord,
	            success : function(user) {
	            	console.log(user);
	            	var title = '<div>Gefundener Benutzer: ';
	            	var userInfo = "<p>Name: " + "<span class = 'userName'>"  + user.name + 	"</span></p><p>Email: " + "<span class = 'userEmail'>" + user.email + "</span></p></div>";
 	 	    	    jQuery('.searchResult').html(title + userInfo);
	 	    	    jQuery('.doubleButtons').css("display", "inline");
	 	    	},
	 	    	fail: function(XMLHttpRequest, textStatus) {
 	 	    	    jQuery('.searchResult').html(textStatus);
		  }
	    });
	});
});